package com.fit.beans;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fit.interfaces.BorrowI;
import com.fit.interfaces.CarI;
import com.fit.interfaces.User;
import com.fit.service.BorrowsI;

@Entity
public class BorrowBean implements BorrowI {

	@Id @GeneratedValue
	private long id;
	
	@Basic
	private String name;
	
	@Basic
	private Date dateOfBorrow;
	
	@Temporal(TemporalType.DATE)
	private Date returnDateOfBorrow;
	
	@Basic
	private double summary;
	
	@ManyToOne(targetEntity=UserBean.class)
	private User user;
	
//	@ManyToMany(targetEntity = CarBean.class, mappedBy="borrows")
//	private List<CarI> cars = new LinkedList<CarI>();
	
	@ManyToOne(targetEntity = CarBean.class)
	private CarI car;
	
	
	

//	public List<CarI> getCars() {
//		return cars;
//	}
//
//	public void setCars(List<CarI> cars) {
//		this.cars = cars;
//	}

	public CarI getCar() {
		return car;
	}

	public void setCar(CarI car) {
		this.car = car;
	}

	/* (non-Javadoc)
	 * @see com.fit.beans.BorrowI#getId()
	 */
	public long getId() {
		return id;
	}

	/* (non-Javadoc)
	 * @see com.fit.beans.BorrowI#setId(long)
	 */
	public void setId(long id) {
		this.id = id;
	}

	/* (non-Javadoc)
	 * @see com.fit.beans.BorrowI#getName()
	 */
	public String getName() {
		return name;
	}

	/* (non-Javadoc)
	 * @see com.fit.beans.BorrowI#setName(java.lang.String)
	 */
	public void setName(String name) {
		this.name = name;
	}

	/* (non-Javadoc)
	 * @see com.fit.beans.BorrowI#getDateOfBorrow()
	 */
	public Date getDateOfBorrow() {
		return dateOfBorrow;
	}

	/* (non-Javadoc)
	 * @see com.fit.beans.BorrowI#setDateOfBorrow(java.util.Date)
	 */
	public void setDateOfBorrow(Date dateOfBorrow) {
		this.dateOfBorrow = dateOfBorrow;
	}

	/* (non-Javadoc)
	 * @see com.fit.beans.BorrowI#getUser()
	 */
	public User getUser() {
		return user;
	}

	/* (non-Javadoc)
	 * @see com.fit.beans.BorrowI#setUser(com.fit.interfaces.User)
	 */
	public void setUser(User user) {
		this.user = user;
	}
	
	
	public Date getReturnDateOfBorrow() {
		return returnDateOfBorrow;
	}

	public void setReturnDateOfBorrow(Date returnDateOfBorrow) {
		this.returnDateOfBorrow = returnDateOfBorrow;
	}

	public double getSummary() {
		return summary;
	}

	public void setSummary(double summary) {
		this.summary = summary;
	}

	public void executeBorrowCreation(String name,Date dateOfBorrow,Date returnDateOfBorrow,double summary,User user,CarI car){
//		List<CarI> tmp = new LinkedList<CarI>();
//		tmp.add(car);
//		setCars(tmp);
		setCar(car);
		setName(name);
		setDateOfBorrow(dateOfBorrow);
		setUser(user);
		setReturnDateOfBorrow(returnDateOfBorrow);
		setSummary(summary);
		user.getBorrows().add(this);
		car.getBorrows().add(this);
		
	}
	
}
